package com.imti.mapper;

import com.imti.model.Repo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface RepoMapper {
    @Select("<script>SELECT count(*) FROM `t_repo` WHERE 1=1" +
            "<if test=\"name!=null and name!=''\"> AND `name` LIKE CONCAT('%',#{name},'%')</if>" +
            "</script>")
    public int getRepoCount(Repo repo);



    @Select("<script>SELECT * FROM t_repo  WHERE 1=1" +
            "<if test=\"r.name!=null and r.name!=''\"> AND `name` LIKE CONCAT('%',#{r.name},'%')</if>" +
            "limit #{p.pageIndex},#{p.pageLimit}</script>")
    @Results(id = "RepoMap",value = {
            @Result(column = "user_id",property = "userId"),
            @Result(column = "create_time",property = "createTime")
    })
    List<Repo> findAllRepo(Map map);

    @Insert("INSERT INTO t_repo (name,user_id,create_time) VALUES (#{name},#{userId},#{createTime})")
    public Integer addRepo(Repo repo);

    @Update("UPDATE t_repo SET NAME = #{name},user_id=#{userId},create_time=#{createTime} WHERE id = #{id}")
    Integer updateRepo(Repo repo);

    @Select("SELECT * FROM t_repo AS tr WHERE tr.id= #{id} ")
    @ResultMap("RepoMap")
    public Repo getRepoById(Integer id);
}
